﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Index : System.Web.UI.Page
{
    string generateForumdiv(CForum cf)
    {
        string R="";
        string name=cf.m_name;
        string fid = cf.m_fid.ToString();
        string photo="avatar/forum_"+cf.m_fid+".png";
        string description=cf.m_description;
        string todaynum=cf.topicTodayCount.ToString();


        string url = "Forum.aspx?fid="+fid+"&page=1";
        R+="<div class=\"index_item\"><div class=\"index_item_pic\">";
        R+="<a href=\""+url+"\">";
        R+="<img src=\""+photo+"\"/></a>";
        R+="</div><div class=\"index_item_info\">";
        R += "<a href=\"" + url + "\">" + name + "</a>";
        R+="<span>(今日:" + todaynum + ")</span><p>";
        R+=description;
        R+="</p></div></div>";

        return R;
    }
    string emptyFormdiv()
    {
        return "<div class=\"index_item\"></div>";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        CGeneral.CheckLogin(Request, Session);

        CIndex index = new CIndex();
        index.GetAllForum();
        int sepcial = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ProbForumId"].ToString());
        CForum probForum = null;
        foreach (CForum cf in index.forumlist)
        {
            if(cf.m_fid==sepcial)
            {
                probForum = cf;
                continue;
            }
            Literal_forum.Text += generateForumdiv(cf);
        }
        if((index.forumlist.Count()-1)%2==1)
        {
            Literal_forum.Text += emptyFormdiv();
        }
        Literal_forum.Text += generateForumdiv(probForum);
        Literal_forum.Text += emptyFormdiv();
        Literal_lasttopic.Text = Topic.getLastTopic();

    }
}